//  Source Control Tag:
//  $Id: popUp.js,v 1.8 2004/06/25 01:16:40 seb9911 Exp $
//  Name: popUp.js
//  
//  Description: Functions to pop up windows. The standard
//		options for a pop up created by this script are:
//		"status=no,resizable=yes,scrollbars=yes,left=5,top=5"
//

//  Usage for popUp():
// 		popUp(full URL, height, width);
// 		popUp('http://boeing.com', 500, 300);
//
//  'popUp' is used to create or reuse a single pop up window. This should
//  be used in most cases to prevent the proliferation of many pop-ups
//	and also to keep pop-ups from being buried by other windows.
var PUwin;

function popUp(pu_item, h, w)
{
	var newwin = null;

	if(typeof(PUwin) == 'undefined' || PUwin.closed)
	{
		// create new window and load with help_item
		newwin = window.open("","","width=" + w + ",height=" +
			h + ",status=no,resizable=yes,scrollbars=yes,left=5,top=5");

		if(newwin != null)
		{
			if (newwin.opener == null)
				newwin.opener = self;
			newwin.location.href = pu_item;
		}
		PUwin = newwin;
		PUwin.focus();
	} else { 
		// bring existing window to the top, load with URL
		PUwin.location = pu_item;
		PUwin.resizeTo(w,h);
		PUwin.focus();
	}
}

//
//  Usage for popUpNewWin():
// 		popUpNewWin(full URL, height, width, options, [window_id]);
// 		popUpNewWin('http://boeing.com', 500, 300, '', 'mywindow');
//
//  'popUpNewWin' is used to pop up new windows rather than using the
//  target='_blank' method. This provides focus control of the pop-ups,
//  and gives the parent visibility via a window.popups[] object that
// 	works like an associative array. 
//  
//	The [options] parameter allows you to add additional options such
//	as "toolbar=on" and other options in addition to the defaults.
//	However, these options are generally discouraged for use in a pop-ups.
//  If no additional options are desired, just pass a null string.
//
//  There are five items in the array that are available to the user of
//  this script.  They are as follows:
//    1) The URL
//    2) the Width of the popup window
//    3) the Height of the popup window
//    4) Options for the popup window, such as if it will have a status bar, 
//       a tool bar, a menubar, etc.  (options will be enclosed in single
//       quotes, for example 'menubar,toolbar,status')
//    5) and the popup window name which will be enclosed in single quotes
//  
//  To utilize the cascading capability of this script, simply designate
//  a unique name for each popup window.  For instance, if the desire is to
//  open three separate popup windows which are cascaded, the links would
//  look something like this:
//    <a href="popUpNewWin('your 1st link', 500, 300, '', 'popup_1');">
//    <a href="popUpNewWin('your 2nd link', 500, 300, '', 'popup_2');">
//    <a href="popUpNewWin('your 3rd link', 500, 300, '', 'popup_3');">
//
//	If the optional [window_id] is left out, 'default' is used as the id. 
//	The [window_id] argument must start with a letter and have no spaces
//	or dashes.
//
//	To access a pop-up window object from the parent window, use
//		var mypopupwindow = window.popups['mywindow'];
window.popups = new Object();
var win_count = 0;
var win_left = 5; 
var win_top = 5; 
function popUpNewWin(pu_item, h, w, options)
{
	var newwin = null;
	var win_id;
	if(arguments.length >4)
	{
		win_id = arguments[4];
	}
	else
	{
		win_id = 'default';
	}

	if(typeof(window.popups[win_id]) == 'undefined' ||
			window.popups[win_id].closed)
	{ 	

		// set top and left to cascade windows 
		//alert ("that popup is not open yet - open a new one");
		var l = win_left + (15 * win_count);
		var t = win_top + (15 * win_count);
		var open_options = "width=" + w + ",height=" + h +
			",status=no,resizable=yes,scrollbars=yes,"+
			options+",left="+l+",top="+t;

		// create new window and load url
		newwin = window.open("", win_id, open_options);
		if(newwin != null)
		{
			if (newwin.opener == null)
				newwin.opener = self;
			newwin.location.href = pu_item;
		}
		window.popups[win_id] = newwin;
		window.popups[win_id].focus();
		win_count++;
	} else {
		// bring existing window to the top, load with content
		alert ("the name of the popup window requested is open already \nbring to front and use it");
		window.popups[win_id].location = pu_item;
		window.popups[win_id].resizeTo(w,h);
		window.popups[win_id].focus();
	}
}